import {defineStore, StoreDefinition} from 'pinia'


interface Customer {
  username: string,
  user_id: number,
  permissions: string[],
  axios_path: string
}

// 第一个参数是应用程序中 store 的唯一 id

export const useStore: StoreDefinition<"main", Customer, {}> = defineStore<"main", Customer, {}>('main', {

  state: ():Customer => ({
    axios_path: '3',  // 记录当前打开的标签页，当标签页切换时更改，这样就能知道是一厂还是二厂发出的指令
    username: '未登录',
    user_id: 0,
    permissions: [],  // 用户有权查看的组件的名称

  }),
  // @ts-ignore
  persist: {
    enabled: true,
    strategies: [
      { storage: localStorage, paths: ['username', 'axios_path', 'permissions', 'user_id'] }
    ],
  },
})